/*
 * @Author: liutongchao 1923236391@qq.com
 * @Date: 2023-04-28 11:24:35
 * @LastEditors: liutongchao 1923236391@qq.com
 * @LastEditTime: 2023-06-25 15:20:56
 * @FilePath: \greenbeeadmin\controllers\admin\admin.go
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
package controllers

import (
	adminService "greenbeeadmin/controllers/admin/service"
	greenbee "greenbeeadmin/controllers/greenbee"
	"greenbeeadmin/models"
)

// 系统设置
type SystemSetController struct {
	greenbee.AdminBaseController
}

func (c *SystemSetController) Get() {
	var systemSetService adminService.SystemSetService
	var systemSetting models.SystemSetting
	systemSetting.Types = "system"
	field := []string{"Types"}
	data, _ := systemSetService.GetData(systemSetting, field)
	c.Data["systemSetting"] = data

	c.TplName = "admin/system/setting.html"
}

// 提交数据
func (c *SystemSetController) Post() {
	var data interface{}
	id, _ := c.GetInt("id", 0)
	file_max_size, _ := c.GetInt("file_max_size", 0)
	web_name := c.GetString("web_name", "")
	portal_url := c.GetString("portal_url", "")
	file_types := c.GetString("file_types", "")
	record := c.GetString("record", "")
	gonggao := c.GetString("gonggao", "")
	tongji := c.GetString("tongji", "")
	powerby := c.GetString("powerby", "")
	var systemSetService adminService.SystemSetService
	var systemSetting models.SystemSetting
	systemSetting.Types = "system"
	field := []string{"Types"}
	_, err := systemSetService.GetData(systemSetting, field)
	systemSetting.FileMaxSize = file_max_size
	systemSetting.WebName = web_name
	systemSetting.PortalUrl = portal_url
	systemSetting.FileTypes = file_types
	systemSetting.Record = record
	systemSetting.Gonggao = gonggao
	systemSetting.Tongji = tongji
	systemSetting.Powerby = powerby

	if err == nil || id > 0 {
		//更新
		updateField := []string{"FileMaxSize", "WebName", "PortalUrl", "FileTypes", "Record", "Gonggao", "Tongji", "Powerby"}

		systemSetService.Edit(systemSetting, id, updateField)
	} else {
		//添加
		systemSetService.Add(systemSetting)
	}
	c.SuccessJson(0, data, 1)
}
